<?php
  require(dirname(__FILE__).'/global.php'); 
  require(ROOT.'/isLogin.php');
  
  $bar = $_POST['bar'];
  if(!isset($bar))
  {
      $smarty->assign("code","verify.php");
      $smarty->display('createBar.html');
  }
  else
  {
      $sql = "select BarName from talking_bar where BarName = '$bar'";
      $bars = $db->query($sql);
      if(count($bars)>0)
      {
          echo '贴吧已存在';
          exit();
      }
      $barID = DataConverter::initSerialNo();
      $barImg = 'static/images/default.gif';
      $barDes = $_POST['des'];
      $barAdmin = $_SESSION['user']['id'];
      $barCreateTime = DateUtil::get_YY_mm_dd_HH_mm_ss();
      $sql = "insert into talking_bar(BarID,BarName,BarImg,BarDescribe,BarAdmin,BarCreateTime) values('$barID','$bar','$barImg','$barDes','$barAdmin','$barCreateTime')";
      $db->execute($sql);
      header("Location: bar.php?id=$barID");
  }
  $db->close();
  $log->logInfo("[URL]$visitorURL"); 
?>
